package dataStructure.Recursion;

/**
 * @author lhn
 * @date 2024-08-28 14:44
 */

public class RecursionTest {
    public static void main(String[] args) {
        test(5);

        int num = 3;
        System.out.println(
                num + "的阶乘是" + factorial(num)
        );

    }

    public static void test(int n){
        if (n > 2) {
            test(n - 1 );
        }
        System.out.println("n is " + n);
//        n is 2
//        n is 3
//        n is 4
//        n is 5
    }

    public static int factorial(int n){
        if (n == 1) {
            return 1;
        }
        return n * factorial(n - 1);
    }

}
